package me.jessyan.mvparms.demo.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.xrecyclerview.XRecyclerView;
import com.example.xrecyclerview.refresh.SwipyRefreshLayout;
import com.github.megatronking.svg.support.SVGDrawable;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DoubleClickUtils;
import com.jess.arms.utils.PerfectClickListener;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import me.jessyan.mvparms.demo.di.component.fragment.DaggerBrandComponent;
import me.jessyan.mvparms.demo.di.module.fragment.BrandModule;
import me.jessyan.mvparms.demo.drawables.ic_arrow_right;
import me.jessyan.mvparms.demo.drawables.ic_yellow_exclamation_point;
import me.jessyan.mvparms.demo.mvp.contract.fragment.BrandContract;
import me.jessyan.mvparms.demo.mvp.presenter.fragment.BrandPresenter;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.ui.activity.other.SearchActivity;
import me.jessyan.mvparms.demo.mvp.ui.activity.store.MainStoreActivity;
import me.jessyan.mvparms.demo.mvp.ui.activity.store.StoreActivity;
import me.jessyan.mvparms.demo.mvp.ui.adapter.FragBrandVpAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.SlideTabView;
import me.jessyan.mvparms.demo.mvp.ui.widget.tsnackbar.TSnackbar;
import me.jessyan.mvparms.demo.utils.NetSnackbarUtil;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 品牌馆 一级 fragment
 */
public class BrandFragment extends OneLevelBaseFragment<BrandPresenter> implements BrandContract.View, View.OnClickListener {

    ViewPager viewPager;
    SlideTabView slideTabView;
    TextView searchTv;
    CoordinatorLayout coorl;


    @Inject
    List<String> tabStrs;

    public static BrandFragment newInstance() {
        BrandFragment fragment = new BrandFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerBrandComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .brandModule(new BrandModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.home_brand_fragment, container, false);
        viewPager = view.findViewById(R.id.viewpager);
        slideTabView = view.findViewById(R.id.tab);
        searchTv = view.findViewById(R.id.search_tv);
        coorl = view.findViewById(R.id.coorl);
        view.findViewById(R.id.anchor_store_tv).setOnClickListener(this);
        searchTv.setOnClickListener(this);
        view.findViewById(R.id.experience_tv).setOnClickListener(this);
        return view;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        initPage();


    }
    @Override
    public void onReceiveBack() {
        if(isVisible) NetSnackbarUtil.getInstance().checkAndShow(coorl,getActivity());
    }
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser) NetSnackbarUtil.getInstance().checkAndShow(coorl,getActivity());
    }

    private void initPage() {


        FragBrandVpAdapter<String> adapter = new FragBrandVpAdapter<String>(R.layout.item_frag_brand_vp, tabStrs, getContext());
        viewPager.setOffscreenPageLimit(1);
        viewPager.setAdapter(adapter);
        slideTabView.initTab(tabStrs, viewPager);
        adapter.setListener(new FragBrandVpAdapter.FragBrandVpAdapterListener() {
            @Override
            public void getItem(View view, Boolean data) {
                startActivity(new Intent(getActivity(), StoreActivity.class));
            }
        });

    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public void onClick(View view) {
        if (DoubleClickUtils.getInstance().isDouble(view)) {
            return;
        }
        switch (view.getId()) {
            case R.id.search_tv:
                startActivity(new Intent(getActivity(), SearchActivity.class));
                break;
            //主力店
            case R.id.anchor_store_tv:
                startActivity(new Intent(getActivity(), MainStoreActivity.class));
                break;
            case R.id.experience_tv:

                break;
            default:
        }
    }


}
